package cn.tedu.shoot;
import java.util.Random;
import java.awt.image.BufferedImage;
import java.awt.Graphics;
public abstract class  FlyingObject {
	// 活着的--显示本图象 爆破的--显示爆破图像，删除的--不再窗口上。
	public static final int LIFE = 0;
	public static final int DEAD = 1;
	public static final int REMOVE = 2;
	protected int state = LIFE;
	protected int width;
	protected int height;
	protected int x;
	protected int y;
	public FlyingObject(int width,int height){
		this.width = width;
		this.height = height;
		Random rand = new Random();
		x = rand.nextInt(World.WIDTH-width);
		y = -this.height;
	}
	public FlyingObject(int width,int height,int x,int y) {
		this.width = width;
		this.height = height;
		this.x = x;
		this.y = y;	
	}
	public abstract void step();	
	//设计getImage()
	public abstract BufferedImage getImage();
	
	
	
	public void paintObject(Graphics g) {
		g.drawImage(getImage(),x,y,null);
	}	
	public boolean isLife() {
		return state==LIFE;
	}
	
	public boolean isDead() {
		return state==DEAD;
	}
	public boolean isRemove() {
		return state==REMOVE;
	}
	public boolean outOfBouds() {//判断敌人是否越界
			return this.y>=World.HEIGHT;
		}
	public boolean hit(FlyingObject other) {
		int x1 = this.x-other.width;
		int x2 = this.x+this.width;
		int y1 = this.y-other.height;
		int y2 = this.y+this.height;
		int x = other.x;
		int y = other.y;
		return x>=x1&&x<=x2
				&&
				y>=y1&&y<=y2;
	}
	
	public void goDead() {
		state = DEAD;//addDoubleFire  addLife
	}
}